#ifndef H_RCGD_HOLDOVER_H
#define H_RCGD_HOLDOVER_H

#define	PHASE_INSERT_AGING_TABLE		0
#define	PHASE_INIT_AGING_CALCULATION	1
#define	PHASE_CALCULATE_AGING_MATRIX	2
#define PHASE_CALCULATE_AGING_SOLUTION	3
#define PHASE_AGING_CONTROL				4



#define AGING_FACTOR	0.6



#define START_POINT_OF_MAKING_AGING_TABLE 	320
#define	MINIMUM_TABLE_BOUND_OF_AGING_CONTROL	180
//#define	MINIMUM_TABLE_BOUND_OF_AGING_CONTROL	60
#define MAX_AGING_TABLE_SIZE 800

typedef struct Aging_Table_S{
	float	DAC;
	float	TEMPER;
	int		STEP;
}Aging_Table_;

typedef struct HoldoverCONTROL_S{
	Aging_Table_	AgingTable[MAX_AGING_TABLE_SIZE];
	Aging_Table_	AgingTable_new[MAX_AGING_TABLE_SIZE];
/*
	float			NominalAgingDAC;
	float			NominalAgingTEMPER;
*/
	int				NUMofAgingTable;
	char			Phase;
	short int		NumOfCal;
	short int		AgingTableSize;
	int				AgingTableIndex;

	int 	StepCounter;
	float	InitialTEMPER;

	float	AgingReference;
    int  	AvgTimeOffset,PrevAvgTimeOffset;

} HoldoverCONTROL_;


typedef struct{

	char	flag;
	char	step;
	double	normal_x,normal_y;
	double	plus_x,plus_y;
	double	minus_x,minus_y;

}HoldoverCalc_;

extern HoldoverCONTROL_	HoldoverCONTROL;
extern HoldoverCalc_ HoldoverCalc;

extern void InsertAgingTable(int, float , float);

extern void calc_matrix(void);
extern void add_matrix(double, double, double);
extern void holdover_calculation(void);
extern void holdover_calculation_new(void);

extern double AgingMatrix[4][4],AgingMatrix_backup[4][4];
extern double Aging_sol[3];

void filter_get_linear_fit( double x[], double y[], int s, double* a, double* b);
void Init_HOLDOVER();

#endif
